# Contributor: Grigory Kirillov <txgk@bk.ru>
# Maintainer:
pkgname=libzn_poly
pkgver=0.9.2
pkgrel=2
pkgdesc="Library for polynomial arithmetic over Z/nZ"
url="https://gitlab.com/sagemath/zn_poly"
arch="all"
# https://gitlab.com/sagemath/zn_poly/-/blob/master/COPYING
license="( GPL-2.0-only OR GPL-3.0-only ) AND GPL-2.0-or-later AND LGPL-2.1-or-later"
makedepends="gmp-dev python3"
subpackages="$pkgname-static $pkgname-dev"
source="https://gitlab.com/sagemath/zn_poly/-/archive/$pkgver/zn_poly-$pkgver.tar.gz"
builddir="$srcdir/zn_poly-$pkgver"

build() {
	## We need to explicitly set PIC because ld yields:
	# src/misc.o: warning: relocation against `ZNP_version_string' in read-only section `.text'
	# src/mulmid.o: relocation R_X86_64_PC32 against symbol `ZNP_tuning_info' can not be used when making a shared object; recompile with -fPIC
	# final link failed: bad value
	export CFLAGS="$CFLAGS -fPIC"

	python3 makemakefile.py \
		--cflags="${CFLAGS/-Os/-O3}" \
		--cxxflags="${CXXFLAGS/-Os/-O3}" \
		--ldflags="$LDFLAGS" > GNUmakefile
	make all libzn_poly.so
}

check() {
	make check
}

package() {
	install -Dm644 include/zn_poly.h -t "$pkgdir"/usr/include/zn_poly
	install -Dm644 include/wide_arith.h -t "$pkgdir"/usr/include/zn_poly
	install -Dm755 libzn_poly.a -t "$pkgdir"/usr/lib
	install -Dm755 libzn_poly-"$pkgver".so -t "$pkgdir"/usr/lib
	ln -s libzn_poly-"$pkgver".so "$pkgdir"/usr/lib/libzn_poly-"${pkgver%.*}".so
	ln -s libzn_poly-"${pkgver%.*}".so "$pkgdir"/usr/lib/libzn_poly.so
}

sha512sums="
472994bdefdcc353983a5c831af0a49777582c422d069867802a268d8ab4c7b040cd88284dc066632e893d3a4cf5b4a88ac5f1910504b8b5d3c84306c56333bd  zn_poly-0.9.2.tar.gz
"
